#pragma once
#include <iostream>
#include <sys/epoll.h>
const static int gsize = 128;
class epoller
{
public:
    epoller()
    {
        _epfd = epoll_create(12);
        if (_epfd < 0)
        {
            LOG(LogLevel::FATAL) << "epoll create fatal!";
            exit(1);
        }
        LOG(LogLevel::INFO) << "create epoll fd success: " << _epfd;
    };
    void AddEvent(int fd, uint32_t events)
    {
        struct epoll_event ev;
        ev.data.fd = fd;
        ev.events = events;
        int n = epoll_ctl(_epfd, EPOLL_CTL_ADD, fd, &ev);
        if (n != 0)
        {
            // 这里面是添加失败了
        }
        // 到这里是添加成功了
        std::cout << " 添加成功 " << std::endl;
    }
    void DelEvent()
    {
    }
    void ModEvent(int fd, uint32_t events)
    {
        struct epoll_event ev;
        ev.data.fd = fd;
        ev.events = events;
        int n = epoll_ctl(_epfd, EPOLL_CTL_MOD, fd, &ev);
        if (n != 0)
        {
            // 这里面是添加失败了
        }
        // 到这里是添加成功了
        std::cout << " Mod添加成功 " << std::endl;
    }
    int wait(struct epoll_event ev[], int timeout)
    {
        int n = epoll_wait(_epfd, ev, gsize, timeout);
        (void)n;
        return n;
    }

    ~epoller() {

    };

private:
    int _epfd;
};

// class poller
// {
//     public:

//     private:

// };